package student.aistar.day11;

import java.util.*;

public class ForMapDemo {
    public static void main(String[] args) {
        Map<Integer, String> maps = new HashMap<>();
        maps.put(1, "java");
        maps.put(2, "python");

        Set<MyEntry<Integer, String>> sets =  print(maps);

        Iterator<MyEntry<Integer, String>> iterator = sets.iterator();
        while (iterator.hasNext()){
            MyEntry<Integer, String> next = iterator.next();
            System.out.println(next.getKey()+"--->" + next.getValue());

        }

    }

    private static Set<MyEntry<Integer, String>> print(Map<Integer, String> maps) {
        String string = maps.toString();
        String strMap = string.substring(1, string.length() - 1);
        String[] split = strMap.split(",");
        //1=java
        //2=python
        Set<MyEntry<Integer, String>> sets = new HashSet<>();
        for (String s : split) {
            String trim = s.trim();
            String[] split1 = trim.split("=");
            Integer key = Integer.valueOf(split1[0]);
            String value = split1[1];

            MyEntry<Integer, String> myEntry = new MyEntry<>();
            myEntry.setKey(key);
            myEntry.setValue(value);

            sets.add(myEntry);
        }

        return sets;
    }


}
class MyEntry<K, V>{
    private K key;

    private V value;

    public MyEntry() {
    }

    public MyEntry(K key, V value) {
        this.key = key;
        this.value = value;
    }

    public K getKey() {
        return key;
    }

    public void setKey(K key) {
        this.key = key;
    }

    public V getValue() {
        return value;
    }

    public void setValue(V value) {
        this.value = value;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("MyEntry{");
        sb.append("key=").append(key);
        sb.append(", value=").append(value);
        sb.append('}');
        return sb.toString();
    }
}